package pl.vm.domain;

import pl.vm.domain.exceptions.InvalidStateException;
import pl.vm.domain.interfaces.Classification;
import pl.vm.domain.interfaces.RoundState;
import pl.vm.domain.simulator.PointsCalculator;
import pl.vm.domain.simulator.SimplePointsCalculator;

public class RoundFrozen implements RoundState {

	private RoundImpl round;
	private PointsCalculator calculator = new SimplePointsCalculator();		

	public RoundFrozen(RoundImpl round) {
		this.round = round;
	}
	
	@Override
	public void setPlayerStatistics(Player player, Statistics stats)
			throws InvalidStateException {
		double points = calculator.calculatePlayerPoints(stats, player);
		round.getStatistics().put(player, stats);
		round.getPlayersPoints().put(player, points);
		round.getSeazon().addPointsForPlayer(player, points);
	}

	@Override
	public void changePlayerStatistics(Player player, Statistics stats)
			throws InvalidStateException {
		double pointsToAdd = calculator.calculatePlayerPoints(stats, player);
		double pointsToSubstract = round.getPlayersPoints().get(player);
		round.getStatistics().put(player, stats);
		round.getPlayersPoints().put(player, pointsToAdd);
		round.getSeazon().removePointsForPlayer(player, pointsToSubstract);
		round.getSeazon().addPointsForPlayer(player, pointsToAdd);
	}
	
	@Override
	public boolean addTeam(VirtualTeam team) throws InvalidStateException {
		throw new InvalidStateException();
	}

	@Override
	public void close() throws InvalidStateException {
		round.setState(round.CLOSED);
	}

	@Override
	public void freeze() throws InvalidStateException {
		throw new InvalidStateException();
	}

	@Override
	public Classification getClassification() {
		return round.classification;
	}

	@Override
	public boolean changeTeam(VirtualTeam oldTeam, VirtualTeam newTeam) throws InvalidStateException {
		throw new InvalidStateException();
	}
}
